package com.yunkeji.api.dataUpload.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yunkeji.api.dataUpload.service.SysUploadService;
import com.yunkeji.common.enums.app.AppBranchEnum;
import com.yunkeji.common.utils.DataUploadUtils;
import com.yunkeji.dao.domain.SysUpload;
import com.yunkeji.dao.mapper.SysUploadMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 数据上报 业务层处理
 *
 * @author 雷擎宇
 */
@RequiredArgsConstructor
@Service
public class SysUploadServiceImpl implements SysUploadService {

    private final SysUploadMapper mapper;

    private SysUpload getOne(String oaid) {
        return mapper.selectOne(Wrappers.lambdaQuery(SysUpload.class).eq(SysUpload::getOaid, oaid));
    }

    @Override
    public void upload(String oaid, DataUploadUtils.DataType dataType, int branch) {
        switch (AppBranchEnum.getByCode(branch)) {
            case 陌对安卓oppo:
                SysUpload upload = getOne(oaid);
                if (Objects.isNull(upload)) {
                    return;
                }
                DataUploadUtils.oppoUpload(upload.getOaid(), dataType, upload.getAdid());
                break;
            case 陌对安卓vivo:
                DataUploadUtils.vivoUpload(oaid, dataType);
                break;
            case 陌对安卓小米:
                DataUploadUtils.xiaoMiUpload(oaid, dataType);
                break;
            default:
                break;
        }
    }

//    @Override
//    public void upload(String oaid, DataUploadUtils.DataType dataType, int branch, String payId, Long payAmount) {
//        switch (AppBranchEnum.getByCode(branch)) {
//            case 陌对安卓oppo版本:
//                SysUpload upload = getOne(oaid);
//                if (Objects.isNull(upload)) {
//                    return;
//                }
//                DataUploadUtils.oppoUpload(upload.getOaid(), dataType, upload.getAdid(), payId, payAmount);
//                break;
//            case 陌对安卓vivo版本:
//                DataUploadUtils.vivoUpload(oaid, dataType);
//                break;
//            default:
//                break;
//        }
//    }
}
